package org.esk.dablog.model.forum;

import org.esk.dablog.model.Entry;

import javax.persistence.*;
import java.util.Set;
import java.util.HashSet;

/**
 * This class
 * User: esk
 * Date: Dec 12, 2006
 * Time: 3:05:54 PM
 * $Id:$
 *
 * @hibernate.subclass discriminator-value="3"
 */
@Entity
@DiscriminatorValue("3")
public class ForumTopicEntry extends Entry {

    private Set<ForumPostEntry> posts;

    /**
     * Adds new post to the topic
     *
     * @param post
     */
    public void addPost(ForumPostEntry post) {
        if (posts == null) {
            posts = new HashSet();
        }
        posts.add(post);
        post.setParent(this);
    }

    /**
     * @return
     * @hibernate.set lazy="true"
     * inverse="true"
     * cascade="all-delete-orphan"
     * where="entry_type=4"
     * order-by="ENTRY_DATE"
     * @hibernate.key column="PARENT_ENTRY_ID"
     * @hibernate.one-to-many class="org.esk.dablog.model.forum.ForumPostEntry"
     */
//TODO possibly Forum posts will stop saving!!!!!
    @OneToMany
    @JoinColumn(name = "PARENT_ENTRY_ID")
    public Set<ForumPostEntry> getPosts() {
        return posts;
    }

    public void setPosts(Set<ForumPostEntry> posts) {
        this.posts = posts;
    }

}
